/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package modelo;

import javax.swing.JLabel;
import javax.swing.JProgressBar;
import javax.swing.JSlider;

/**
 *
 * @author sebastian
 */
public class Llave {
    
    private int tipoLlave;
    private int nivelApertura;//?
    private float caudal; // Lts/seg
    private static final float velocidadAgua = 2; // m/s
    private float area; // cm^2
    
    private JLabel valCaudal;
    private JProgressBar medNivel;
    private JSlider indicadorApertura;

    public Llave(int tipoLlave, JSlider indicadorApertura, JLabel valCaudal, JProgressBar medNivel) {
        this.tipoLlave = tipoLlave;
        this.nivelApertura = nivelApertura;
        this.indicadorApertura = indicadorApertura;
        this.valCaudal = valCaudal;
        this.medNivel = medNivel;
        
        if (tipoLlave == 1) {
            this.area = 25;// cm ^2
            this.caudal = (this.area/10) * velocidadAgua; // Lts/seg
        }
        else{
            this.area = 0;
            this.caudal = 0;
        }
    }

    public int getTipoLlave() {
        return tipoLlave;
    }

    public void setTipoLlave(int tipoLlave) {
        this.tipoLlave = tipoLlave;
    }

    public int getNivelApertura() {
        return nivelApertura;
    }

    public void setNivelApertura(int nivelApertura) {
        this.nivelApertura = nivelApertura;
    }

    public float getCaudal() {
        return caudal;
    }

    public void setCaudal(float caudal) {
        this.caudal = caudal;
    }
    
    //Metodos de control:
    public void aumentarNivelApertura(int velocidad){
        if (this.tipoLlave == 1 && this.area <= 50) {
            this.area += velocidad;
            if (this.area > 50) {
                this.area = 50;
            }
        }
        else{
            if (this.area < 50) {
                this.area += 25;
            }
        }
        this.indicadorApertura.setValue((int)(this.area));
        this.caudal = velocidadAgua * (this.area/10);
        this.medNivel.setValue((int)this.area);
        this.valCaudal.setText(String.valueOf(this.caudal) + " Lts/seg");
    }
    
    public void disminuirNivelApertura(int velocidad){
        if (this.tipoLlave == 1) {
            this.area -= velocidad;
        }
        else{
            if (this.area > 0) {
                this.area -= 25;
                if (this.area < 0) {
                    this.area = 0;
                }
            }
        }
        this.indicadorApertura.setValue((int)(this.area));
        this.caudal = velocidadAgua * (this.area/10);
        this.medNivel.setValue((int)this.area);
        this.valCaudal.setText(String.valueOf(this.caudal) + " Lts/seg");
    }
}